<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="author" content="Aubrey Dugger" />

<meta name="date" content="2017-05-01" />

<title>Evaluate water budget partitioning with rwrfhydro</title>



<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>



<link href="data:text/css;charset=utf-8,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23header%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20both%3B%0Amargin%3A%200%200%2010px%2010px%3B%0Apadding%3A%204px%3B%0Awidth%3A%20400px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Aborder%2Dradius%3A%205px%3B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Afont%2Dsize%3A%2013px%3B%0Aline%2Dheight%3A%201%2E3%3B%0A%7D%0A%23TOC%20%2Etoctitle%20%7B%0Afont%2Dweight%3A%20bold%3B%0Afont%2Dsize%3A%2015px%3B%0Amargin%2Dleft%3A%205px%3B%0A%7D%0A%23TOC%20ul%20%7B%0Apadding%2Dleft%3A%2040px%3B%0Amargin%2Dleft%3A%20%2D1%2E5em%3B%0Amargin%2Dtop%3A%205px%3B%0Amargin%2Dbottom%3A%205px%3B%0A%7D%0A%23TOC%20ul%20ul%20%7B%0Amargin%2Dleft%3A%20%2D2em%3B%0A%7D%0A%23TOC%20li%20%7B%0Aline%2Dheight%3A%2016px%3B%0A%7D%0Atable%20%7B%0Amargin%3A%201em%20auto%3B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dcolor%3A%20%23DDDDDD%3B%0Aborder%2Dstyle%3A%20outset%3B%0Aborder%2Dcollapse%3A%20collapse%3B%0A%7D%0Atable%20th%20%7B%0Aborder%2Dwidth%3A%202px%3B%0Apadding%3A%205px%3B%0Aborder%2Dstyle%3A%20inset%3B%0A%7D%0Atable%20td%20%7B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dstyle%3A%20inset%3B%0Aline%2Dheight%3A%2018px%3B%0Apadding%3A%205px%205px%3B%0A%7D%0Atable%2C%20table%20th%2C%20table%20td%20%7B%0Aborder%2Dleft%2Dstyle%3A%20none%3B%0Aborder%2Dright%2Dstyle%3A%20none%3B%0A%7D%0Atable%20thead%2C%20table%20tr%2Eeven%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Ap%20%7B%0Amargin%3A%200%2E5em%200%3B%0A%7D%0Ablockquote%20%7B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Apadding%3A%200%2E25em%200%2E75em%3B%0A%7D%0Ahr%20%7B%0Aborder%2Dstyle%3A%20solid%3B%0Aborder%3A%20none%3B%0Aborder%2Dtop%3A%201px%20solid%20%23777%3B%0Amargin%3A%2028px%200%3B%0A%7D%0Adl%20%7B%0Amargin%2Dleft%3A%200%3B%0A%7D%0Adl%20dd%20%7B%0Amargin%2Dbottom%3A%2013px%3B%0Amargin%2Dleft%3A%2013px%3B%0A%7D%0Adl%20dt%20%7B%0Afont%2Dweight%3A%20bold%3B%0A%7D%0Aul%20%7B%0Amargin%2Dtop%3A%200%3B%0A%7D%0Aul%20li%20%7B%0Alist%2Dstyle%3A%20circle%20outside%3B%0A%7D%0Aul%20ul%20%7B%0Amargin%2Dbottom%3A%200%3B%0A%7D%0Apre%2C%20code%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0Aborder%2Dradius%3A%203px%3B%0Acolor%3A%20%23333%3B%0Awhite%2Dspace%3A%20pre%2Dwrap%3B%20%0A%7D%0Apre%20%7B%0Aborder%2Dradius%3A%203px%3B%0Amargin%3A%205px%200px%2010px%200px%3B%0Apadding%3A%2010px%3B%0A%7D%0Apre%3Anot%28%5Bclass%5D%29%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Acode%20%7B%0Afont%2Dfamily%3A%20Consolas%2C%20Monaco%2C%20%27Courier%20New%27%2C%20monospace%3B%0Afont%2Dsize%3A%2085%25%3B%0A%7D%0Ap%20%3E%20code%2C%20li%20%3E%20code%20%7B%0Apadding%3A%202px%200px%3B%0A%7D%0Adiv%2Efigure%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0Aimg%20%7B%0Abackground%2Dcolor%3A%20%23FFFFFF%3B%0Apadding%3A%202px%3B%0Aborder%3A%201px%20solid%20%23DDDDDD%3B%0Aborder%2Dradius%3A%203px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Amargin%3A%200%205px%3B%0A%7D%0Ah1%20%7B%0Amargin%2Dtop%3A%200%3B%0Afont%2Dsize%3A%2035px%3B%0Aline%2Dheight%3A%2040px%3B%0A%7D%0Ah2%20%7B%0Aborder%2Dbottom%3A%204px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Apadding%2Dbottom%3A%202px%3B%0Afont%2Dsize%3A%20145%25%3B%0A%7D%0Ah3%20%7B%0Aborder%2Dbottom%3A%202px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Afont%2Dsize%3A%20120%25%3B%0A%7D%0Ah4%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23f7f7f7%3B%0Amargin%2Dleft%3A%208px%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Ah5%2C%20h6%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23ccc%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Aa%20%7B%0Acolor%3A%20%230033dd%3B%0Atext%2Ddecoration%3A%20none%3B%0A%7D%0Aa%3Ahover%20%7B%0Acolor%3A%20%236666ff%3B%20%7D%0Aa%3Avisited%20%7B%0Acolor%3A%20%23800080%3B%20%7D%0Aa%3Avisited%3Ahover%20%7B%0Acolor%3A%20%23BB00BB%3B%20%7D%0Aa%5Bhref%5E%3D%22http%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0Aa%5Bhref%5E%3D%22https%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0A%0Acode%20%3E%20span%2Ekw%20%7B%20color%3A%20%23555%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Edt%20%7B%20color%3A%20%23902000%3B%20%7D%20%0Acode%20%3E%20span%2Edv%20%7B%20color%3A%20%2340a070%3B%20%7D%20%0Acode%20%3E%20span%2Ebn%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Efl%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Ech%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Est%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Eco%20%7B%20color%3A%20%23888888%3B%20font%2Dstyle%3A%20italic%3B%20%7D%20%0Acode%20%3E%20span%2Eot%20%7B%20color%3A%20%23007020%3B%20%7D%20%0Acode%20%3E%20span%2Eal%20%7B%20color%3A%20%23ff0000%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Efu%20%7B%20color%3A%20%23900%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%20code%20%3E%20span%2Eer%20%7B%20color%3A%20%23a61717%3B%20background%2Dcolor%3A%20%23e3d2d2%3B%20%7D%20%0A" rel="stylesheet" type="text/css" />

</head>

<body>




<h1 class="title toc-ignore">Evaluate water budget partitioning with rwrfhydro</h1>
<h4 class="author"><em>Aubrey Dugger</em></h4>
<h4 class="date"><em>2017-05-01</em></h4>



<div id="background" class="section level1">
<h1>Background</h1>
<p>We are using WRF-Hydro to predict streamflow for Fourmile Creek at the Orodell USGS gage for the 2013 snowmelt period. We ran WRF-Hydro with NoahMP as the LSM for a 3-year spinup period and then did a daily run for 5 months starting March 1, 2013. We want to evaluate the predicted water budget partitioning over this snowmelt period.</p>
<p>Load the rwrfhydro package.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(<span class="st">&quot;rwrfhydro&quot;</span>)</code></pre></div>
<p>Set a data path to the Fourmile Creek test case.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">dataPath &lt;-<span class="st"> '~/wrfHydroTestCases/Fourmile_Creek_testcase_v2.0'</span></code></pre></div>
</div>
<div id="import-modelled-datasets" class="section level1">
<h1>Import modelled datasets</h1>
<p>Calculate basin-averaged LSM water fluxes. The LSM was run at 1km resolution and the high-res hydro grid was 100m resolution, so our aggregation factor is 10. We only have 1 basin in our model domain, and our basin ID is 1. To speed up the netcdf file reads, we are going to use R’s multi-core capability and run this summary over 3 cores.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(doMC)
<span class="kw">registerDoMC</span>(<span class="dv">3</span>)
modLdasoutWb1h.allrt.fc &lt;-<span class="st"> </span><span class="kw">ReadLdasoutWb</span>(<span class="kw">paste0</span>(dataPath, <span class="st">'/run.FullRouting'</span>), 
                                         <span class="kw">paste0</span>(dataPath, <span class="st">'/DOMAIN/Fulldom_hires_hydrofile.Fourmile100m.nc'</span>), 
                                         <span class="dt">mskvar=</span><span class="st">&quot;basn_msk&quot;</span>, <span class="dt">basid=</span><span class="dv">1</span>, <span class="dt">aggfact=</span><span class="dv">10</span>, <span class="dt">parallel=</span><span class="ot">TRUE</span>)</code></pre></div>
<p>Calculate basin-averaged routing water fluxes.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">modRtout1h.allrt.fc &lt;-<span class="st"> </span><span class="kw">ReadRtout</span>(<span class="kw">paste0</span>(dataPath, <span class="st">'/run.FullRouting'</span>), 
                                 <span class="kw">paste0</span>(dataPath, <span class="st">'/DOMAIN/Fulldom_hires_hydrofile.Fourmile100m.nc'</span>), 
                                 <span class="dt">mskvar=</span><span class="st">&quot;basn_msk&quot;</span>, <span class="dt">basid=</span><span class="dv">1</span>, <span class="dt">parallel=</span><span class="ot">TRUE</span>)</code></pre></div>
<p>Import groundwater outflow model output.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">modGwout.allrt.fc &lt;-<span class="st"> </span><span class="kw">ReadGwOut</span>(<span class="kw">paste0</span>(dataPath, <span class="st">'/run.FullRouting/GW_outflow.txt'</span>))</code></pre></div>
</div>
<div id="evaluate-the-predicted-water-budget" class="section level1">
<h1>Evaluate the predicted water budget</h1>
<p>Calculate a water budget for the basin. Our modelled soil depths were 100, 300, 600, and 1000 mm, which match the defaults (therefore we do not need to specify). This model run had all routing options (subsurface, overland, groundwater, and channel) turned on, so we are providing rtout and gwout dataframes and switching sfcrt to TRUE. Our basin area is 63.1 km<sup>2</sup>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">wb.allrt.fc &lt;-<span class="st"> </span><span class="kw">CalcNoahmpWatBudg</span>(modLdasoutWb1h.allrt.fc, <span class="dt">rtoutDf=</span>modRtout1h.allrt.fc, 
                                 <span class="dt">gwoutDf=</span>modGwout.allrt.fc, <span class="dt">sfcrt=</span><span class="ot">TRUE</span>, <span class="dt">basarea=</span><span class="fl">63.1</span>)</code></pre></div>
<p>Take a look at the results. All output values are in mm.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">wb.allrt.fc</code></pre></div>
<table>
<caption>(continued below)</caption>
<colgroup>
<col width="15%"></col>
<col width="15%"></col>
<col width="16%"></col>
<col width="15%"></col>
<col width="17%"></col>
<col width="20%"></col>
</colgroup>
<thead>
<tr class="header">
<th align="left">LSM_PRCP</th>
<th align="left">LSM_ECAN</th>
<th align="left">LSM_ETRAN</th>
<th align="left">LSM_EDIR</th>
<th align="left">LSM_DELSWE</th>
<th align="left">LSM_DELCANWAT</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">524.2</td>
<td align="left">29.75</td>
<td align="left">135.7</td>
<td align="left">228</td>
<td align="left">0</td>
<td align="left">7.925e-07</td>
</tr>
</tbody>
</table>
<table>
<caption>Table continues below</caption>
<colgroup>
<col width="19%"></col>
<col width="19%"></col>
<col width="19%"></col>
<col width="19%"></col>
<col width="21%"></col>
</colgroup>
<thead>
<tr class="header">
<th align="left">LSM_SFCRNOFF</th>
<th align="left">LSM_UGDRNOFF</th>
<th align="left">LSM_DELSOILM</th>
<th align="left">HYD_QSTRMVOL</th>
<th align="left">HYD_DELSFCHEAD</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">34.52</td>
<td align="left">81.2</td>
<td align="left">39.72</td>
<td align="left">9.921</td>
<td align="left">1.786e-07</td>
</tr>
</tbody>
</table>
<table>
<caption>Table continues below</caption>
<colgroup>
<col width="16%"></col>
<col width="16%"></col>
<col width="19%"></col>
<col width="15%"></col>
<col width="20%"></col>
<col width="11%"></col>
</colgroup>
<thead>
<tr class="header">
<th align="left">HYD_QBDRY</th>
<th align="left">HYD_GWOUT</th>
<th align="left">WB_SFCRNOFF</th>
<th align="left">WB_GWOUT</th>
<th align="left">WB_DELGWSTOR</th>
<th align="left">ERROR</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">0</td>
<td align="left">76.61</td>
<td align="left">9.921</td>
<td align="left">76.61</td>
<td align="left">4.589</td>
<td align="left">-0.07125</td>
</tr>
</tbody>
</table>
<table style="width:49%;">
<colgroup>
<col width="15%"></col>
<col width="16%"></col>
<col width="16%"></col>
</colgroup>
<thead>
<tr class="header">
<th align="left">RUN_FRAC</th>
<th align="left">EVAP_FRAC</th>
<th align="left">STOR_FRAC</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">0.1651</td>
<td align="left">0.7505</td>
<td align="left">0.08453</td>
</tr>
</tbody>
</table>
<p>Plot the water budget as a pie chart.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">PlotWatBudg</span>(wb.allrt.fc)</code></pre></div>
<p><img src="" width="600" height="600" /></p>
<p>Note that we are calculating the water budget for March-July only, so we see significant change in storage from a melting snowpack. Calculating the water budget for a full water year would likely result in a much smaller change in storage and the other water flux components would sum to close to 100%.</p>
<p>Plot the water budget as a bar chart.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">PlotWatBudg</span>(wb.allrt.fc, <span class="st">&quot;bar&quot;</span>)</code></pre></div>
<p><img src="" width="600" height="600" /></p>
</div>



<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
